package com.sun.designpatternsdemo

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.GridLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.sun.designpatternsdemo.adapter.AdapterActivity
import com.sun.designpatternsdemo.base.BaseActivity
import com.sun.designpatternsdemo.bridge.BridgeActivity
import com.sun.designpatternsdemo.builder.BuilderActivity
import com.sun.designpatternsdemo.chainofresopnsibility.ChainOfResponsibilityActivity
import com.sun.designpatternsdemo.command.CommandActivity
import com.sun.designpatternsdemo.composite.CompositeActivity
import com.sun.designpatternsdemo.databinding.ActivityMainBinding
import com.sun.designpatternsdemo.decorator.DecoratorActivity
import com.sun.designpatternsdemo.facade.FacadeActivity
import com.sun.designpatternsdemo.factory.FactoryActivity
import com.sun.designpatternsdemo.flyweight.FlyWeightActivity
import com.sun.designpatternsdemo.interpreter.InterpreterActivity
import com.sun.designpatternsdemo.iterator.IteratorActivity
import com.sun.designpatternsdemo.mediator.MediatorActivity
import com.sun.designpatternsdemo.memento.MementoActivity
import com.sun.designpatternsdemo.observer.ObserverActivity
import com.sun.designpatternsdemo.prototype.PrototypeActivity
import com.sun.designpatternsdemo.proxy.ProxyActivity
import com.sun.designpatternsdemo.singleton.SingletonActivity
import com.sun.designpatternsdemo.state.StateActivity
import com.sun.designpatternsdemo.strategy.StrategyActivity
import com.sun.designpatternsdemo.templatemethod.TemplateMethodActivity
import com.sun.designpatternsdemo.visitor.VisitorActivity

class MainActivity : BaseActivity<ActivityMainBinding>() {
    private val patterns = mutableListOf(
        "观察者模式", "工厂模式",
        "单例设计模式", "策略模式",
        "适配器模式", "命令模式",
        "装饰者模式", "外观模式",
        "模板方法模式", "状态模式",
        "建造者模式", "原型模式",
        "享元模式", "代理模式",
        "桥接模式", "组合模式",
        "迭代器模式", "中介者模式",
        "备忘录模式", "解释器模式",
        "责任链模式", "访问者模式"
    )
    private val classes = mutableListOf(
        ObserverActivity::class.java, FactoryActivity::class.java,
        SingletonActivity::class.java, StrategyActivity::class.java,
        AdapterActivity::class.java, CommandActivity::class.java,
        DecoratorActivity::class.java, FacadeActivity::class.java,
        TemplateMethodActivity::class.java, StateActivity::class.java,
        BuilderActivity::class.java, PrototypeActivity::class.java,
        FlyWeightActivity::class.java, ProxyActivity::class.java,
        BridgeActivity::class.java, CompositeActivity::class.java,
        IteratorActivity::class.java, MediatorActivity::class.java,
        MementoActivity::class.java, InterpreterActivity::class.java,
        ChainOfResponsibilityActivity::class.java, VisitorActivity::class.java
    )
    private val TAG = "MainActivity"

    override fun layoutId(): Int = R.layout.activity_main

    override fun initView(savedInstanceState: Bundle?) {
        mDataBind = DataBindingUtil.setContentView(this, R.layout.activity_main)
        mDataBind.rvList.apply {
            layoutManager = GridLayoutManager(this@MainActivity, 2)
            adapter = object : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_main) {
                override fun convert(holder: BaseViewHolder, item: String) {
                    holder.setText(R.id.content, item)
                }
            }.apply {
                setList(patterns)
                setOnItemClickListener { _, _, position ->
                    Log.e(TAG, "onCreate:mainAdapter ")
                    startActivity(Intent(this@MainActivity, classes[position]))
                }
            }
        }
    }
}